/*
 *
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License version 2 as 
 * published by the Free Software Foundation.
 *
 * traits.cpp is for what ...
 *
 * Version: ***: traits.cpp  Wed Nov 23 21:32:01 2011 poponion Exp $
 *
 * Authors:
 *   Author poponion
 *          Email: huangcm85@gmail.com
 *          Blog : http://www.poponion.info
 *     -some work detail if you want 
 *
 */

#include<stdio.h>

struct base_tag
{
};

struct pointer_tag
{
};

template<typename T>
struct print_traits
{
  typedef typename T::print_category print_category;
};

template<typename T>
struct print_traits<T *>
{
  typedef pointer_tag print_category;
};

template<>
struct print_traits<int>
{
  typedef base_tag print_category;
};

template<>
struct print_traits<int*>
{
  typedef pointer_tag print_category;
};

template<typename T>
void print(T t)
{
  doprint(t, typename print_traits<T>::print_category());
}

template<typename T>
void doprint(T t, base_tag)
{
  fprintf(stderr, "base_tag\n");
}

template<typename T>
void doprint(T t, pointer_tag)
{
  fprintf(stderr, "pointer tag\n");
}

struct demo
{
  int a;
  typedef base_tag print_category;
};

int main(int argc, char *argv[])
{
  struct demo  base;
  struct demo *base_pointer = &base;
  print(base);
  print(base_pointer);
  int integer = 0;
  int * pi = &integer;
  print(integer);
  print(pi);
}
